package com.example.projectjava.service;


import com.example.projectjava.dao.AddressDao;
import com.example.projectjava.dao.LogisticDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AddressService {

    @Autowired
    AddressDao addressDao;//spring会自动将userDao注入到此类为(自动为该属性赋值)

    public  int insertAddress(String address_id,String recipient,String address,String phone){
        return addressDao.insertAddress(address_id,recipient,address,phone);
    }

    public int deleteAddress(String address_id) {
        int res = addressDao.deleteAddress(address_id);
        if (res <= 0) {
            throw new RuntimeException("该地址信息不存在");
        } else {
            return 1;
        }
    }

    public List<Map<String, Object>> queryAllAddress() {
        return addressDao.queryAllAddress();
    }

    public int updateAddress(String address_id, String recipient, String address, String phone) {
        int res = addressDao.updateAddress(address_id, recipient, address, phone);
        if (res <= 0) {
            throw new RuntimeException("该地址信息不存在");
        }
        return 1;
    }
}
